package cn.iocoder.yudao.module.blog.convert.casecomment;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.jiucase.vo.commentvo.AppBlogCaseCommentRespVO;
import cn.iocoder.yudao.module.blog.controller.app.post.commentvo.AppBlogPostCommentRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.postcomment.BlogPostCommentDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.casecomment.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.casecomment.BlogCaseCommentDO;

/**
 * 案例评论 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogCaseCommentConvert {

    BlogCaseCommentConvert INSTANCE = Mappers.getMapper(BlogCaseCommentConvert.class);

    BlogCaseCommentDO convert(BlogCaseCommentCreateReqVO bean);

    BlogCaseCommentDO convert(BlogCaseCommentUpdateReqVO bean);

    BlogCaseCommentRespVO convert(BlogCaseCommentDO bean);

    List<BlogCaseCommentRespVO> convertList(List<BlogCaseCommentDO> list);

    PageResult<BlogCaseCommentRespVO> convertPage(PageResult<BlogCaseCommentDO> page);

    List<BlogCaseCommentExcelVO> convertList02(List<BlogCaseCommentDO> list);

    default AppBlogCaseCommentRespVO convertApp(BlogCaseCommentDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }


        AppBlogCaseCommentRespVO appBlogCaseCommentRespVO = new AppBlogCaseCommentRespVO();
        appBlogCaseCommentRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogCaseCommentRespVO.setCaseId(bean.getCaseId());
        appBlogCaseCommentRespVO.setId(bean.getId());
        appBlogCaseCommentRespVO.setCreateTime(bean.getCreateTime());
        appBlogCaseCommentRespVO.setMainCommentId(bean.getMainCommentId());
        appBlogCaseCommentRespVO.setMemberId(bean.getMemberId());
        appBlogCaseCommentRespVO.setRespondCommentId(bean.getRespondCommentId());
        appBlogCaseCommentRespVO.setContent(bean.getContent());

        return appBlogCaseCommentRespVO;
    }

    default List<AppBlogCaseCommentRespVO> convertAppList(List<BlogCaseCommentDO> blogCaseCommentDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogCaseCommentRespVO> list = new ArrayList<>();
        blogCaseCommentDOList.forEach(blogCaseCommentDO -> {
            list.add(convertApp(blogCaseCommentDO, memberMap.get(blogCaseCommentDO.getMemberId())));
        });

        return list;
    }
    default PageResult<AppBlogCaseCommentRespVO> convertAppPage(PageResult<BlogCaseCommentDO> page, Map<Long, MemberUserRespDTO> memberMap ){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogCaseCommentRespVO> pageResult = new PageResult<AppBlogCaseCommentRespVO>();
        List<AppBlogCaseCommentRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
